home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The X-Philes (2nd Revision)
/
The X-Philes Number 1 (1995).iso
/
xphiles
/
hp48_2
/
vsrc.tar
/
voyager7_src
/
find.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-27
|
3KB
|
181 lines
/*
// Abstract:
// FIND---Searching for Comment
//
// The Searhing for Comment module supports searching portions of
// The comment files for the specified (partial) comment.
//
// Author:
// Derek S. Nickel
//
// Creation date:
// 16 January 1991
//
// History:
// V01-001 Derek S. Nickel 16-JAN-1991
// Original.
//
*/
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include "find.h"
#include "index.h"
#include "memory.h"
#include "pager.h"
#include "tree.h"
#define MAX_LINE 256
typedef struct _finddata_t finddata_t;
struct _finddata_t {
long matches;
bin5_t offset;
bin5_t start;
bin5_t end;
char *data;
TextFile *tf;
char cbuf[MAX_LINE];
char dbuf[MAX_LINE];
};
static void search_port(int port_no, bin5_t start, bin5_t end,
long *matches, char *rest);
static int write_one_line(node_t *node, finddata_t *db);
/***********************************************************************
Messages.
***********************************************************************/
#define vgr__nomatches \
"%%VOYAGER-I-NOMATCHES, no matches found\n"
#define vgr__matched \
"%%VOYAGER-I-MATCHED, found %ld matches\n"
/***********************************************************************
find_comment
***********************************************************************/
void find_comment(bin5_t start, bin5_t end, char *data)
{
long matches = 0;
/*
// Search each port in turn.
*/
strupr(data);
if (ports[0].loaded) search_port(0, start, end, &matches, data);
if (ports[1].loaded) search_port(1, start, end, &matches, data);
if (ports[2].loaded) search_port(2, start, end, &matches, data);
/*
// Print summary.
*/
pager(0);
if (matches == 0)
printf(vgr__nomatches);
else
printf(vgr__matched, matches);
}
/***********************************************************************
search_port
***********************************************************************/
static void search_port(int port_no, bin5_t start, bin5_t end,
long *matches, char *data)
{
bin5_t min_adr;
bin5_t max_adr;
finddata_t db;
cond_value sys_status;
/*
// Define allowable search range for this port.
*/
min_adr = ports[port_no].min_adr;
max_adr = ports[port_no].max_adr;
/*
// Verify correct sequencing.
*/
if (start > end) {
bin5_t tmp;
tmp = start;
start = end;
end = tmp;
}
/*
// Search this port?
*/
if ((start < min_adr && end < min_adr) ||
(start > max_adr && end > max_adr))
return;
/*
// Force start amd end into range.
*/
if (start < min_adr) start = min_adr;
if (end > max_adr) end = max_adr;
/*
// Search for comment.
*/
db.matches = 0;
db.offset = min_adr;
db.start = start;
db.end = end;
db.tf = ports[port_no].ca_file;
db.data = data;
/*
// Search for comments.
*/
sys_status = traverse_tree(
&db.tf->root,
write_one_line,
&db );
*matches += db.matches;
}
static int write_one_line(node_t *node, finddata_t *db)
{
char *cbufp = db->cbuf;
char *dbufp = db->dbuf;
bin5_t adr = node->key + db->offset;
if (db->start <= adr && adr <= db->end) {
if (!node->deleted) {
fseek(db->tf->f, node->value, SEEK_SET);
fgets(cbufp, MAX_LINE, db->tf->f);
db->cbuf[strlen(cbufp)-1] = '\0';
cbufp += 6;
strupr(strcpy(dbufp,cbufp));
if (strstr(dbufp,db->data)) {
db->matches++;
pager(0);
printf("%05lX %s\n", adr, cbufp);
}
}
}
return 1;
}